package com.alks.common.utils.excelUtils.fluExcel;

import com.alks.common.utils.stringUtils.ZStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class JxlsUtils {
    public JxlsUtils() {
    }

    public String dateFmt(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    public String floatRound3(Float number) {
        return number == null ? "0.000" : String.format("%.3f", number);
    }

    public String floatRoundN(Float number, int n) {
        if (number == null) {
            number = 0.0F;
        }

        return String.format("%." + n + "f", number);
    }

    public String getStrResult(String qcResult, String... strings) {
        if (strings != null && strings.length != 0) {
            if (strings.length == 1) {
                return strings[0];
            } else {
                for(int i = 0; i < strings.length; i += 2) {
                    if (strings[i].equals(qcResult) && i + 1 < strings.length) {
                        return strings[i + 1];
                    }
                }

                return strings[strings.length - 1];
            }
        } else {
            return qcResult;
        }
    }

    public String boolResult(Boolean bool, String yesStr, String noStr) {
        if (ZStringUtils.isNull(bool)) {
            return noStr;
        } else {
            return bool ? yesStr : noStr;
        }
    }

    public String reasonTypeStr(Integer reasonType) {
        if (ZStringUtils.isNull(reasonType)) {
            return "";
        } else {
            switch (reasonType) {
                case 1:
                    return "大底不良";
                case 2:
                    return "鞋面不良";
                case 3:
                    return "包装不良";
                case 4:
                    return "成型不良";
                case 5:
                    return "外协不良";
                case 99:
                    return "其他原因";
                default:
                    return "";
            }
        }
    }

    public String oemOutTypeStr(String outType) {
        if (ZStringUtils.isNull(outType)) {
            return "";
        } else {
            switch (outType) {
                case "I":
                    return "入库";
                case "O":
                    return "出库";
                default:
                    return "";
            }
        }
    }
}
